import os
from django.contrib import admin
from .client import GitClient
from .models import GitRepo, LocalGitRepo
# Register your models here.

class GitRepoAdmin(admin.ModelAdmin):
    list_display = [f.name for f in GitRepo._meta.fields]

class LocalGitRepoAdmin(admin.ModelAdmin):
    actions = ["gitCloneForce"]
    list_display = [f.name for f in LocalGitRepo._meta.fields]
    @admin.action(description="Git Clone Force")
    def gitCloneForce(self, request, queryset):
        for localGitRepo in queryset:
            print(localGitRepo.repo.url)
            print(localGitRepo.localGitRepoHub)
            print(localGitRepo.localGitRepoHome)

            try:
                GitClient.cloneForce(localGitRepo.repo.url, localGitRepo.localGitRepoHome, localGitRepo.localGitRepoHub)
            except Exception as e:
                print(e)
            

admin.site.register(GitRepo, GitRepoAdmin)
admin.site.register(LocalGitRepo, LocalGitRepoAdmin)